//
// itertool - a polynormial and type-safe iterator framework in C++.
//
// Copyright (c) 2021-2025 Feng Cong
//
// Distributed under the MIT Software License
// See accompanying file LICENSE.txt or copy at
// https://opensource.org/licenses/MIT

#pragma once

#include <itertool/itertool_fwd.h>

namespace itertool_test {

// An finite iterator that yields natural number, i.e., a sequence of
// 0, 1, 2, ..., n, where n is a fixed non-negative integer.
// It exists mainly for testing purposes.
class NaturalNumberIterable : public itertool::Iterable<int> {
 public:
  using ItemType = int;

  explicit NaturalNumberIterable(int limit) : limit_(limit) {}
  bool HasNext() override { return now_ < limit_; }
  void Advance() override {
    assert(HasNext());
    ++now_;
  }
  ItemType GetNow() override { return now_; }
  bool IsFinite() override { return true; }
  bool IsResetable() override { return true; }
  void Reset() override { now_ = 0; }
  size_t LengthHint() override { return limit_ - now_; }

 private:
  int now_ = 0;
  const int limit_;
};

inline itertool::Iterator<int> NaturalNumber(int limit) {
  return itertool::MakeIterator<NaturalNumberIterable>(limit);
}

}  // namespace itertool_test
